home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / capbowl.c < prev    next >
C/C++ Source or Header  |  1999-11-15  |  6KB  |  266 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/tms34061.h"
  11. #include "cpu/m6809/m6809.h"
  12.  
  13. unsigned char *capbowl_rowaddress;
  14.  
  15. static unsigned char *raw_video_ram;
  16. static unsigned int  color_count[4096];
  17. static unsigned char dirty_row[256];
  18.  
  19. static int max_col, max_row, max_col_offset;
  20.  
  21. static int  capbowl_tms34061_getfunction(int offset);
  22. static int  capbowl_tms34061_getrowaddress(int offset);
  23. static int  capbowl_tms34061_getcoladdress(int offset);
  24. static int  capbowl_tms34061_getpixel(int col, int row);
  25. static void capbowl_tms34061_setpixel(int col, int row, int pixel);
  26.  
  27. #define PAL_SIZE  0x20
  28.  
  29. /***************************************************************************
  30.  
  31.   Start the video hardware emulation.
  32.  
  33. ***************************************************************************/
  34. static int capbowl_vertical_interrupt(void)
  35. {
  36.     return M6809_INT_FIRQ;
  37. }
  38.  
  39. static struct TMS34061interface tms34061_interface =
  40. {
  41.     capbowl_tms34061_getfunction,
  42.     capbowl_tms34061_getrowaddress,
  43.     capbowl_tms34061_getcoladdress,
  44.     capbowl_tms34061_getpixel,
  45.     capbowl_tms34061_setpixel,
  46.     0,
  47.     capbowl_vertical_interrupt,  /* Vertical interrupt causes a FIRQ */
  48. };
  49.  
  50. int capbowl_vh_start(void)
  51. {
  52.     int i;
  53.  
  54.     if ((raw_video_ram = malloc(256 * 256)) == 0)
  55.     {
  56.         return 1;
  57.     }
  58.  
  59.     // Initialize TMS34061 emulation
  60.     if (TMS34061_start(&tms34061_interface))
  61.     {
  62.         free(raw_video_ram);
  63.         return 1;
  64.     }
  65.  
  66.     max_row = Machine->drv->visible_area.max_y;
  67.     max_col = Machine->drv->visible_area.max_x;
  68.     max_col_offset = (max_col + 1) / 2 + PAL_SIZE;
  69.  
  70.     // Initialize color areas. The screen is blank
  71.     memset(raw_video_ram, 0, 256*256);
  72.     palette_init_used_colors();
  73.     memset(color_count, 0, sizeof(color_count));
  74.     memset(dirty_row, 1, sizeof(dirty_row));
  75.  
  76.     for (i = 0; i < max_row * 16; i+=16)
  77.     {
  78.         palette_used_colors[i] = PALETTE_COLOR_USED;
  79.         color_count[i] = max_col + 1;  // All the pixels are pen 0
  80.     }
  81.  
  82.     return 0;
  83. }
  84.  
  85.  
  86.  
  87. /***************************************************************************
  88.  
  89.   Stop the video hardware emulation.
  90.  
  91. ***************************************************************************/
  92. void capbowl_vh_stop(void)
  93. {
  94.     free(raw_video_ram);
  95.  
  96.     TMS34061_stop();
  97. }
  98.  
  99.  
  100. /***************************************************************************
  101.  
  102.   TMS34061 callbacks
  103.  
  104. ***************************************************************************/
  105.  
  106. static int capbowl_tms34061_getfunction(int offset)
  107. {
  108.     /* The function inputs (FS0-FS2) are hooked up the following way:
  109.  
  110.        FS0 = A8
  111.        FS1 = A9
  112.        FS2 = grounded
  113.      */
  114.  
  115.     return (offset >> 8) & 0x03;
  116. }
  117.  
  118.  
  119. static int capbowl_tms34061_getrowaddress(int offset)
  120. {
  121.     /* Row address (RA0-RA8) is not dependent on the offset */
  122.     return *capbowl_rowaddress;
  123. }
  124.  
  125.  
  126. static int capbowl_tms34061_getcoladdress(int offset)
  127. {
  128.     /* Column address (CA0-CA8) is hooked up the A0-A7, with A1 being inverted
  129.        during register access. CA8 is ignored */
  130.     int col = (offset & 0xff);
  131.  
  132.     if (!(offset & 0x300))
  133.     {
  134.         col ^= 0x02;
  135.     }
  136.  
  137.     return col;
  138. }
  139.  
  140.  
  141. static void capbowl_tms34061_setpixel(int col, int row, int pixel)
  142. {
  143.     int off = ((row << 8) | col);
  144.     int penstart = row << 4;
  145.  
  146.     int oldpixel = raw_video_ram[off];
  147.  
  148.     raw_video_ram[off] = pixel;
  149.  
  150.     if (row > max_row || col >= max_col_offset) return;
  151.  
  152.     if (col >= PAL_SIZE)
  153.     {
  154.         int oldpen1 = penstart | (oldpixel >> 4);
  155.         int oldpen2 = penstart | (oldpixel & 0x0f);
  156.         int newpen1 = penstart | (pixel >> 4);
  157.         int newpen2 = penstart | (pixel & 0x0f);
  158.  
  159.         if (oldpen1 != newpen1)
  160.         {
  161.             dirty_row[row] = 1;
  162.  
  163.             color_count[oldpen1]--;
  164.             if (!color_count[oldpen1]) palette_used_colors[oldpen1] = PALETTE_COLOR_UNUSED;
  165.  
  166.             color_count[newpen1]++;
  167.             palette_used_colors[newpen1] = PALETTE_COLOR_USED;
  168.         }
  169.  
  170.         if (oldpen2 != newpen2)
  171.         {
  172.             dirty_row[row] = 1;
  173.  
  174.             color_count[oldpen2]--;
  175.             if (!color_count[oldpen2]) palette_used_colors[oldpen2] = PALETTE_COLOR_UNUSED;
  176.  
  177.             color_count[newpen2]++;
  178.             palette_used_colors[newpen2] = PALETTE_COLOR_USED;
  179.         }
  180.     }
  181.     else
  182.     {
  183.         /* Offsets 0-1f are the palette */
  184.  
  185.         int r = (raw_video_ram[off & ~1] & 0x0f);
  186.         int g = (raw_video_ram[off |  1] >> 4);
  187.         int b = (raw_video_ram[off |  1] & 0x0f);
  188.         r = (r << 4) + r;
  189.         g = (g << 4) + g;
  190.         b = (b << 4) + b;
  191.  
  192.         palette_change_color(penstart | (col >> 1),r,g,b);
  193.     }
  194. }
  195.  
  196.  
  197. static int capbowl_tms34061_getpixel(int col, int row)
  198. {
  199.     return raw_video_ram[row << 8 | col];
  200. }
  201.  
  202. /***************************************************************************
  203.  
  204.   Draw the game screen in the given osd_bitmap.
  205.   Do NOT call osd_update_display() from this function, it will be called by
  206.   the main emulation engine.
  207.  
  208. ***************************************************************************/
  209. void capbowl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  210. {
  211.     int col, row;
  212.     const unsigned char *remapped;
  213.  
  214.  
  215.     if (full_refresh)
  216.     {
  217.         for (row = 0; row <= max_row; row++)  dirty_row[row] = 1;
  218.     }
  219.  
  220.     if (TMS34061_display_blanked())
  221.     {
  222.         fillbitmap(bitmap,palette_transparent_pen,&Machine->drv->visible_area);
  223.         return;
  224.     }
  225.  
  226.     if ((remapped = palette_recalc()) != 0)
  227.     {
  228.         for (row = 0; row <= max_row; row++)
  229.         {
  230.             if (dirty_row[row] == 0)
  231.             {
  232.                 int i;
  233.  
  234.                 for (i = 0;i < 16;i++)
  235.                 {
  236.                     if (remapped[16 * row + i] != 0)
  237.                     {
  238.                         dirty_row[row] = 1;
  239.                         break;
  240.                     }
  241.                 }
  242.             }
  243.         }
  244.     }
  245.  
  246.     for (row = 0; row <= max_row; row++)
  247.     {
  248.         if (dirty_row[row])
  249.         {
  250.             int col1 = 0;
  251.             int row1 = (row << 8 | PAL_SIZE);
  252.             int row2 =  row << 4;
  253.  
  254.             dirty_row[row] = 0;
  255.  
  256.             for (col = PAL_SIZE; col < max_col_offset; col++)
  257.             {
  258.                 int pixel = raw_video_ram[row1++];
  259.  
  260.                 plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel >> 4)  ]);
  261.                 plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel & 0x0f)]);
  262.             }
  263.         }
  264.     }
  265. }
  266.